import {
    reqGetDev,
    reqGetResult,
} from "@/api/newApi/OCAP/index.js";

export default {
    data() {
        return {
            THeight: null,
            loading: false,
            dialogLoading: false,
            Page: { pageNum: 1, pageSize: 20 },
            total: 0,
            tableList: [],//表数据
            deviceNos: [],//设备下拉数组
            //区分
            types: [
                {
                    value: "FPC",
                    label: "FPC",
                },
                {
                    value: "SMT",
                    label: "SMT",
                },
            ],
        }
    },
    computed: {
        //当前用户的路由
        Myroutes() {
            return this.$store.getters.permission_routes;
        },
        //获取当前登陆用户信息
        userInfo() {
            let obj = this.$store.state.user;
            let user =
                this.$store.state.user.post == "超级管理员"
                    ? null
                    : this.$store.state.user.account;
            return Object.assign(obj, { user });
        },
    },
    mounted() {
        this.THeight = (78 * window.innerHeight) / 100;
        this.getInfo();
        this.getDev();
    },
    methods: {
        //给数据加id,Index
        addIdIndex(resData) {
            this.tableList = resData.map((item, index) => {
                return {
                    Index: (this.Page.pageNum - 1) * this.Page.pageSize + index + 1,
                    ...item,
                };
            });
        },
        //获取设备编号下拉框
        async getDev() {
            let res = await reqGetDev({ user: this.userInfo.user });
            if (res.code == 0) {
                this.deviceNos = res.data;
                this.deviceNos.forEach((item) => {
                    item.label1 = item.deviceCode;
                    item.label2 = item.unitNo;
                    item.value = `${item.deviceCode}拼接${item.unitNo}`;//deviceCode+unitNo两个值确定唯一值
                });
            } else {
                this.$modal.msgError(res.message);
            }
        },
        //获取数据
        async getInfo(name) {
            this.loading = true;
            let reqForm = Object.assign({ user: this.userInfo.user }, this.searchForm, this.Page);
            reqForm.deviceCode = this.searchForm.deviceCode ? this.searchForm.deviceCode.split("拼接")[0] : null
            let res = await reqGetResult(reqForm);
            if (res.code == 0) {
                this.addIdIndex(res.data);
                this.total = res.total;
                if (name == "搜索") {
                    this.$modal.msgSuccess("查询成功");
                }
            } else {
                this.$modal.msgError(res.message);
            }
            this.loading = false;
        },
        //搜索
        handleSearch(name) {
            this.Page.pageNum = 1;
            this.getInfo(name);
        },
        //重置
        handleReset(state) {
            this.searchForm = { state }
            this.handleSearch();
        },
    },
    destroyed() {
    },
    beforeDestroy() {

    },
}

